package com.info33.platform.system.util;

import com.info33.platform.system.entity.SysDictionary;

import java.util.Map;

/**
 * @author debj
 * @version 1.0
 * @date 2022/2/18 8:51
 */
public class SysDictionaryUtil {

    private SysDictionaryUtil() {
    }

    /**
     * 根据数据源，获取 id 集合的
     *
     * @param source 数据源
     * @param id     id / ids
     * @return key 集合，逗号分割
     */
    public static String getKeysByIds(Map<Long, SysDictionary> source, Object id) {
        String str = String.valueOf(id);
        if (str.contains(",")) {
            StringBuilder sb = new StringBuilder();
            for (String s : str.split(",")) {
                long l = Long.parseLong(s);
                sb.append(source.containsKey(l) ? source.get(l).getDictionaryKey() : "");
                sb.append(",");
            }
            return sb.substring(0, sb.length() - 1);
        } else {
            long l = Long.parseLong(str);
            return source.containsKey(l) ? source.get(l).getDictionaryKey() : "";
        }
    }

}
